package com.mars.rabbitmq.normal;

import com.mars.rabbitmq.nio.KingClient;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author King
 * @create 2020/8/19 10:54
 */
@Slf4j

@Component
public class KingConsumer {

//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(value = RabbitMqConfig.QUEUE, durable = "true"),
//            exchange = @Exchange(value = RabbitMqConfig.EXCHANGE, ignoreDeclarationExceptions = "true")))
//    public void onMessage(Message message, Channel channel) throws IOException {
//        try {
//            //TODO 处理业务
//            Thread.sleep(5000);
//        } catch (Exception e) {
//            log.error(e.getMessage(), e);
//        }
//        long deliveryTag = message.getMessageProperties().getDeliveryTag();
//        channel.basicAck(deliveryTag, true);
//        log.info("receive--1: " + new String(message.getBody()));
//    }

    public static void main(String[] args) {

        KingClient client = new KingClient(9898, "localhost", "陈晨");
        try {
            client.start();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}
